<?php
require_once __DIR__."/Base_model.php";
class Host_person_model extends Base_model
{
    public function __construct()
    {
        parent::__construct();
        $this->table = "users";
        $this->table1 = "type";
        $this->table2 = "type_sub";
    }

    /**
     *
     */
    public function all($arr){
        $this->db->select('*');
        $this->db->from($this->table);
        //
        $this->db->where("status",2);
        $this->db->where("user_type",1);
        //审核状态筛选
        if(!empty($arr['online'])){
            $this->db->where("is_status",$arr['online']);
        }
        //时间筛选
        if(!empty($arr['start_time']) && !empty($arr['end_time'])){
            $this->db->where("add_time >=",$arr['start_time']);
            $this->db->where("add_time <",$arr['end_time']);
        }
        //关键字筛选
        if(!empty($arr['keyword'])){
            $this->db->like("nick_name",$arr['keyword']);
            $this->db->or_like("user_autograph",$arr['keyword']);
        }

        //分页
        if(!empty($arr['page']) && !empty($arr['limit'])){
            $pages=($arr['page']-1)*$arr['limit'];
            $datas['total']=$this->db->count_all_results("",false);
            $this->db->limit($arr['limit'],$pages);
        }else{
            $datas['total']=$this->db->count_all_results("",false);
        }
        //排序
        $this->db->order_by('add_time',"desc");
        $res = $this->db->get();
        $datas['row']= $res->result_array();
//        echo $this->db->last_query();
        return $datas;
    }
}